﻿-var cdate = (DateTime) ViewData["Date"]
-var schedules = ViewData["Schedules"] as List<Schedule>
-var tasks = ViewData["Tasks"] as List<Task>
-int startHour = (int)ViewData["StartHour"]
-int endHour = (int)ViewData["EndHour"]
-int interval = (int)ViewData["Interval"]
-bool print = ViewData.ContainsKey("print")
-var workingHours = ViewData["WorkingHours"] as Dictionary<int, IWorkingHours>
-var isTaskAdmin = (ViewData["user"] as IUser).HasPermission("TaskAdmin")
=HTMLHelper.HiddenInput("interval",interval)
%div{class=print?"printmode":""}
  %h1
    %img.icon24{src="img/headericons/schedule.png"}
    =cdate.ToString("dd MMMM yyyy")
    -if(!print)
      -if (isTaskAdmin)
        %a.btncreate{href="#",onclick="return createTask()"} <img src="img/buttons/create.gif" title="Создать заявку" width="73" height="23"/>
      %a{href=string.Format("taskschedule.ivp/print/{0}",cdate.ToString("dd.MM.yyyy")),target="_blank"}
        %img{src="img/buttons/print.gif",title="Печать"}
  #tasks
    %table.taskschedule.data
      %tr
        %th{width="7%"}
        -foreach(var s in schedules)
          %th{schedule=s.Id,width="20%"}=s.Name
      -for(int h=startHour;h<endHour;h++)
        -for(int m=0;m<60;m+=interval)
          -string time=string.Format("{0}:{1}",h.AddLeadingZero(2),m.AddLeadingZero(2))
          %tr
            %th.time=time
            -foreach(var s in schedules)
              -var wh = workingHours[s.Id]
              -string cssclass = (wh!=null && wh.IsWorkingTime(h,m)) ? "sc"+s.Id : "greybg"
              -if (isTaskAdmin)
                %td{class=cssclass,onclick=string.Format("return createTask({0},'{1}')",s.Id,cdate.ToString("dd.MM.yyyy")+" "+time)} &nbsp;
              -else
                %td{class=cssclass} &nbsp;
    -foreach(var t in tasks)
      %div{class=string.Format("task sct{0}",t.ScheduleId),time=t.StartDate.ToTimeString(),schedule=t.ScheduleId,duration=t.Duration,onclick=string.Format("return viewTask({0});",t.Id)}
        %p
          =string.Format("№{0} - {1};",t.Id,t.NotarialAction.Name)
          %span=t.Person.FullName